 # -*- coding: utf-8 -*-
import json

def getDictCompanyQualifiList(request):
	
	result_list = []
	
	request.cursor_standard.execute('''
        select qualifi_no,qualifi_name 
        from dict_company_qualifi
    ''')
	rows = request.cursor_standard.fetchall()
	result_dict = {}
	for row in rows:
		result_dict[row['qualifi_no']] = row['qualifi_name']

	#先填充一级
	for row in rows:
		if len(row['qualifi_no']) == 2:
			obj = {}
			obj['id'] = row['qualifi_no']
			obj['state'] = "opened"
			obj['text'] = row['qualifi_name']
			obj['children'] = []
			result_list.append(obj) 
	print(result_list)

	#开始填充二级
	for first_level_obj in result_list:
		print(first_level_obj)
		qualifi_no = first_level_obj['id']
		for row in rows:
			if row['qualifi_no'][:-2] ==  qualifi_no:
				obj = {}
				obj['id'] = row['qualifi_no']
				obj['state'] = "opened"
				obj['text'] = row['qualifi_name']
				obj['children'] = []
				first_level_obj['children'].append(obj)
	
	#开始填充三级
	for first_level_obj in result_list:
		for second_level_obj in first_level_obj['children']:
			qualifi_no = second_level_obj['id']
			for row in rows:
				if row['qualifi_no'][:-2] ==  qualifi_no:
					obj = {}
					obj['id'] = row['qualifi_no']
					obj['state'] = "opened"
					obj['text'] = row['qualifi_name']
					obj['children'] = []
					second_level_obj['children'].append(obj)
		
		 
	return json.dumps(result_list, ensure_ascii=False)












